package com.well.menjin.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.well.menjin.domain.Room;
import com.well.menjin.model.Sort;
import com.well.menjin.service.IRoomService;

/**
 * 
* @ClassName: RoomController  
* @author 姜俊健 
* @date 2016年7月5日 下午8:27:01 
*
 */
@Controller
@RequestMapping ("/room")
public class RoomController extends BaseController {
	@Autowired
	private IRoomService roomservice;
	/**
	 * 
	* @Title: listRooms 
	* @Description: 列出所有房间信息
	* @return String    返回类型 
	* @throws
	 */
	@RequestMapping(value="/listRooms",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String listRooms(@RequestParam(value = "start",required=false)int start,
			@RequestParam(value="limit",required=false) int limit,
			@RequestParam(value="page",required=false) int page,
			@RequestParam(value="sort",required=false) String sorts,
			@RequestParam(value="controllerid",required=false) String controllerid,
			@RequestParam(value="roomname",required=false) String roomname,
			@RequestParam(value="ipaddress",required=false) String ipaddress){
		List<Sort> sorts2 = JSON.parseArray(sorts, Sort.class);
		List<Room> rooms = roomservice.getRooms(start,limit,page,sorts2,controllerid,roomname,ipaddress);
		int totalCount = roomservice.getRoomsCount(controllerid, roomname, ipaddress);
		return jsonBuilder.buildObjListToJson(Long.valueOf(totalCount), rooms, true);
	}

}
